$(function () {
  $.ajax({
    url: 'http://xinzhi_school.jsyixin.com/api/report/getReportDetails',
    beforeSend: function (XMLHttpRequest) {
      XMLHttpRequest.setRequestHeader('token', getUrlKey('token'))
    },
    data: {
      report_id: getUrlKey('report_id'),
      sid: getUrlKey('sid')
    },
    dataType: 'json',
    ContentType: 'application/json',
    type: 'post',
    success: function (res) {
      console.log(res)
      $('.tittle').text(res.data.surveyls_title)
      // 个人信息
      $('.real_name').text(res.data.user_info.real_name)
      $('.student_id').text(res.data.user_info.student_id)
      $('.sex_name').text(res.data.user_info.sex_name)
      $('.grade_title').text(res.data.user_info.grade_title)
      $('.class_title').text(res.data.user_info.class_title)
      // 测评内容
      $('.brief_introduction').append('<p class="retract2 newlineAlignment">' + res.data.brief_introduction + '</p>')
      // 得分（刻度条）
      for (var n = 0; n <= res.data.subsection.segments; n++) {
        var width = (377.98 - (res.data.subsection.segments + 1)) / res.data.subsection.segments
        $('.subsection2').css('width', width)
        $('.subsection').append('<li class="subsection1"> <span>' + n * res.data.subsection.scale + '</span> </li> <li class="subsection2"></li>')
      }
      for (var i = 0; i < res.data.main.length; i++) {
        var a = res.data.main[i]
        // 得分
        $('.score').append('<ul> <li>' + a.dimension + '</li> <li>' + a.score + '</li> <li>' + a.high_score + '</li> <li><div class="articlePoints"><div class="articlePointsScore" style="width:' + a.score + '%;background-color:' + a.color + ';"></div></div></li> </ul>')
        // 结果解释
        $('.explain').append('<div class="tittle3"> <p class="newlineAlignment"><i class="fa fa-caret-right fa-lg triangle"></i>' + a.dimension + '</p> </div> <p class="retract2 newlineAlignment">' + a.explain + '</p>')
        // 建议
        $.getJSON('http://192.168.3.27:8081/static/report/json/aSingleScale.json', function (data) {
          console.log(data)
          for (var i = 0; i < data.data.length; i++) {
            if (data.data[i].title == a.sid) {
              for (var n = 0; n < data.data[i].proposal.length; n++) {
                if (data.data[i].proposal[n].title == a.dimension) {
                  for (var m = 0; m < data.data[i].proposal[n].proposal.length; m++) {
                    $('.proposal').append(data.data[i].proposal[n].proposal[m])
                  }
                }
              }
            }
          }
        })
      }
    }
  })
  function getUrlKey (name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
    var r = window.location.search.substr(1).match(reg)
    if (r != null) return unescape(r[2]); return null
  }
})